<?php

namespace app\index\controller;

use app\index\model\Banner as Banners;
use think\Request;

class Banner extends Base
{
    private $Banner;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->Banner = new Banners();
    }

    public function index()
    {
        $list = $this->Banner->select();
        $this->assign('data', $list);
        return $this->fetch();
    }

    public function edit()
    {
        $list = [
            'status' => '',
            'picture' => '',
            'type' => ''
        ];
        $list['status'] = '';
        $list['status'] = '';
        $id = input('get.id/d');
        if ($id) {
            $list = $this->Banner->where("id = $id")->find();
            $this->assign('data', $list);
        }
        $this->assign('data', $list);
        return $this->fetch();
    }

    public function save()
    {
        $data = input('post.');
        $data['id'] ? $data['update_time'] = time() : $data['create_time'] = time();
        $list = $data['id'] ? $this->Banner->update($data) : $this->Banner->insert($data);
        return $list ? resposer('操作成功', 1) : resposer('操作失败', 0);
    }

    public function delete()
    {
        $id = input('post.id/d');
        $r = resposer('删除失败', 0);
        if ($id) {
            if ($this->Banner->where(['id' => $id])->delete()) {
                $r = resposer('删除成功', 1);
            }
        }
        return $r;
    }
}